module TerminalKeynote
  module DSL
    class Keynote
      attr_reader :keynote

      def initialize
        @keynote = TerminalKeynote::Keynote.new
      end

      def self.load(path)
        dsl = new.tap do |obj|
          obj._load_from(path)
        end

        dsl.keynote
      end

      def _load_from(path)
        path = path.to_s
        instance_eval(File.read(path), path, 1) if path.present?
      end

      # DSL
      def meta(&block)
        block.call(self)
      end

      def title=(value)
        @keynote.title = value
      end

      def author=(value)
        @keynote.author = value
      end

      def created_at=(value)
        @keynote.created_at = value
      end

      def slide(content = nil)
        slide = TerminalKeynote::Slide.new

        if block_given?
          yield(DSL::Slide.new(slide))
        else
          slide.blocks << Block.new(content: content)
        end

        @keynote.slides << slide
      end
    end
  end
end
